from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from core.support import set_cutscene
from core.support import get_game
from items.busdriver import busdriver

class RAM(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        
        # build list of actions
        self.add_action(Tickle)
        self.add_action(StaringContest)
        self.add_action(SingSolo)
        self.add_action(West)
    
    # return description of room.
    def get_description(self):
        if self.has_busdriver():
            return '''
            The absence of that annoying bus driver finally puts a smile on the RAM Ram's face!
            '''
        else:
            return '''
            Uh-oh, you see the abominable RAM Ram!  You've seen many ill-tempered 
            quadrupeds in your day, but the kind that stands on two legs is by far the worst!
            '''

    # return image of room
    def get_image(self):
        if self.has_busdriver():
            return 'ramram_happy.png'
        else:
            return 'ramram.png'
        #return 'ramram.png' or 'ramram_happy'
    
    def get_image_width(self):
        return 'width=100%'
    
    def has_translator(self):
        
        game = get_game()
            
        # does the player have ASCII from the register?
        player = game.get_player()
        
        if "Translator" in player.inventory:
            return True
        # if we get here, player does not have ASCII
        return False
    
    def has_busdriver(self):
        
        game = get_game()
            
        # does the player have ASCII from the register?
        player = game.get_player()
        
        if "busdriver" in player.inventory:
            return True
        # if we get here, player does not have ASCII
        return False

class RAMHandler(BaseHandler):
    
    def get_template(self):
        return 'cpu.html'
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return RAM
    
# define actions for this room

class Tickle(Action):
    def __init__(self):
        Action.__init__(self, "Tickle")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        game = get_game()
        room = game.get_room("ramroom", RAM)
        if room.has_translator():
            return "Tickle the Ram"
        else:
            return "00100011"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'ramroom'
    
    def do_action(self,game,room,request):
        set_cutscene('''
        Didn't your mama ever teach you to not tickle an enormous terrifying monster without asking permission first?''')
        return
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def post_method(self):
        return "post"

class StaringContest(Action):
    def __init__(self):
        Action.__init__(self, "StaringContest")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        game = get_game()
        room = game.get_room("ramroom", RAM)
        if room.has_translator():
            return "Staring contest"
        else:
            return "111011"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'ramroom'
   
    def do_action(self,game,room,request):
        set_cutscene('''
        You begin a contest but lose fairly quickly. The RAM Ram finds it amusing that your staring skills are so baaaaa-d.''')
        return
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def post_method(self):
        return "post"
    
class SingSolo(Action):
    def __init__(self):
        Action.__init__(self, "SingSolo")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        game = get_game()
        room = game.get_room("ramroom", RAM)
        if room.has_translator():
            return "Sing a Song"
        else:
            return "0000111"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'ramroom'
    
    def do_action(self,game,room,request):
        set_cutscene('''
        Great job. Music is always the answer. The RAM Ram seems almost placated, but wishes you would take this annoying sleeping bus driver off his hands...''')
        game = get_game()
        room = game.get_room("ramroom", RAM)
        room.add_item(busdriver())
        return
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def post_method(self):
        return "post"

class West(Action):
    def __init__(self):
        Action.__init__(self, "West")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        game = get_game()
        room = game.get_room("ramroom", RAM)
        if room.has_translator():
            return "Go West"
        else:
            return "10"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        return 'harddrive'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
